﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace zielonka.co.uk.extensions.system.io
{
    // Description:	Returns a string with the content of the input stream
    /*
        //This is only an example. A file could be easily read to a String by using "System.IO.File.ReadAllText"

        using (System.IO.FileStream fs = new System.IO.FileStream(@"c:\test.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read))
        {
            String StreamContent = fs.ReadToEnd();
        }
     */

    public static partial class StreamExtensions
    {
        /// <summary>
        /// Reads the content of the stream
        /// </summary>
        /// <param name="str">Original stream</param>
        /// <returns>Returns a string with the content of the input stream</returns>
        public static String ReadToEnd(this Stream str)
        {
            try { str.Position = 0; }
            catch { }
            using (StreamReader sr = new StreamReader(str))
            {
                return sr.ReadToEnd();
            }
        }
    }
}
